import { AppConfigProvider } from '@/contexts/ConfigProviderContext';
import { SocketProvider } from '@/contexts/SocketProvider';
import { useTranslation } from 'react-i18next';

import Routes from '@/router';
import { useEffect } from 'react';
import { BrowserRouter } from 'react-router-dom';
import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper';
import { useGlobalStore } from './store';

function App(props: any) {
	const basename = qiankunWindow.__POWERED_BY_QIANKUN__ ? '/sub-app' : '/';

	const language = useGlobalStore(state => state.language);
	const { i18n } = useTranslation();
	useEffect(() => {
		i18n.changeLanguage(language);
	}, [i18n, language]);

	return (
		<SocketProvider socket={props.socket}>
			<AppConfigProvider>
				<BrowserRouter basename={basename}>
					<Routes></Routes>
				</BrowserRouter>
			</AppConfigProvider>
		</SocketProvider>
	);
}

export default App;
